<?php

namespace App\Domain;

use App\Model\Arch as ModelArch;

header('content-type:text/html;charset=utf-8');
/*
 * 杂项domail层
 * 领域业务层，负责对领域业务的规则处理，重点关注对数据的逻辑处理、转换和加工，封装并体现特定领域业务的规则
 */

class Arch {

    public function getAll() {
        $rs = [];
        $model = new ModelArch();
        $items = $model->getAll();
        $rs['items'] = $items;
        return $rs;
    }

    public function getOne($id) {
        $rs = [];
        $model = new ModelArch();
        $items = $model->getOne($id);
        foreach ($items as $k => $rows) {
            $img[$k]['url'] = $rows['url'];
            $img[$k]['filesize'] = $rows['filesize'];
            $img[$k]['uptime'] = $rows['uptime'];
            unset($rows['url']);
            unset($rows['filesize']);
            unset($rows['uptime']);
            $rs['items'] = $rows;
        }
        $rs['items']['imglist'] = $img;
        return $rs;
    }

    public function getBatch($tid, $cate, $keyword) {
        $rs = [];
        $model = new ModelArch();
        $items = $model->getBatch($tid, $cate, $keyword);

        if (empty($tid) || (!empty($tid) && !empty($cate))) {
            $rs['items'] = $items;
        } else {
            foreach ($items as $k => $rows) {
                $newrs[$rows['id']][] = $rows;
            }
            foreach ($newrs as $k => $rows) {
                foreach ($rows as $k1 => $rows1) {
                    $img[$k][$k1]['url'] = $rows1['url'];
                    $img[$k][$k1]['filesize'] = $rows1['filesize'];
                    $img[$k][$k1]['uptime'] = $rows1['uptime'];
                    unset($rows1['url']);
                    unset($rows1['filesize']);
                    unset($rows1['uptime']);
                    $newrss[$k] = $rows1;
                }
            }
            foreach ($newrss as $k => $v) {
                $rs['items'][$k] = $v;
                $rs['items'][$k]['imglist'] = $img[$k];
            }
        }
        return $rs;
    }

}
